<?php
namespace Admin\Controller;
use Think\Controller;
class OrderController extends CommonController {
    public function index(){
        $this->rel=M('order_list a')
           ->join("left join agency_goods_list b on a.goods_id=b.goods_id")
           ->join("left join agency_integralmall_list c on a.goods_id=c.integral_goods_id")
            ->join("left join agency_user_address d on a.address_id=d.address_id")
            ->join("left join agency_user_list e on a.user_id=e.user_id")
           ->field('a.* ,b.goods_name,(c.goods_name) as name,d.address ,e.username')
            ->select();
        $this->display();
    }
    public function edit(){
        $id=I('get.id');
       $this->rel=M('order_list a')
           ->join("left join agency_goods_list b on a.goods_id=b.goods_id")
           ->join("left join agency_integralmall_list c on a.goods_id=c.integral_goods_id")
           ->join("left join agency_user_address d on a.address_id=d.address_id")
           ->where(array("a.order_id"=>$id))
           ->field('a.* ,b.goods_name,(c.goods_name) as name,c.integral_goods_id,d.address')->find();

        if(IS_POST){
            $data['order_id']=I('post.order_id');
            $data['order_price']=I('post.order_price');
            $data['payment_price']=I('post.payment_price');
            $data["integral"]=I('post.integral');
            $data['discount']=I('post.discount');
            $data['discount_price']=I('discount_price');
            $data['order_state']=I('order_state');
            $data['address_id']=I('address_id');
            $data['state']=I('state');
            $map['address_id']=I('address_id');
            $map['address']=I('address');
            if (M("order_list")->save($data) or M("user_address")->save($map)){
                $this->success("更改成功!","index",1);die;
            }else{
                $this->error("更改失败","",1);die;
            }


        }
        $this->display();
    }
    public function  del(){
        $id=I("get.id");
        $data['state']=0;
        if(M("order_list")->where(array("order_id"=>$id))->save($data)){
            $this->success("删除成功!","index",1);
        }else{
            $this->error("删除失败!","",1);
        }
    }
     public function  payment(){
        $this->rel=M('order_payment a')
        ->join("left join agency_user_supplier b on a.operator_id=b.operator_id")
        ->join("left join agency_order_list c on a.order_id=c.order_id")
        ->field("a.*,b.name,c.order_sn")
        ->select();
        $this->display();
    }
    public function  paydel(){
       $id=I("get.id");
        $data['ustate']=0;
        if(M("order_payment")->where(array("payment_id"=>$id))->save($data)){
            $this->success("删除成功!","payment",1);
        }else{
            $this->error("删除失败!","",1);
        }
    }
    public function  payedit(){
       $id=I("get.id");
        $data['ustate']=1;
        if(M("order_payment")->where(array("payment_id"=>$id))->save($data)){
            $this->success("恢复成功!","payment",1);
        }else{
            $this->error("恢复失败!","",1);
        }
    }


}